home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 November / CHIP Kasım 1996.iso / ms / webpost / wpsdk.exe / RCDATA / CABINET / WBPOST.CPP < prev    next >
C/C++ Source or Header  |  1996-05-15  |  4KB  |  186 lines

  1. //----------------------------------------------------------------------
  2. //       Copyright (C) 1993-1996 Microsoft Corporation.
  3. //       All rights reserved.
  4. //----------------------------------------------------------------------
  5.  
  6. //----------------------------------------------------------------------
  7. //    WebPost API usage example
  8. //
  9. //  This example allows the user to post files to a web site.
  10. //
  11. //----------------------------------------------------------------------
  12.  
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <stdlib.h>
  17.  
  18. #include <wpapi.h>
  19. #include <wpspi.h>
  20.  
  21. #include "wbpost.h"
  22.  
  23.  
  24. LONG
  25. SimpleWebPost( LPTSTR lpszFileName )
  26. {
  27.     LONG     lRet;
  28.  
  29.     printf("Calling WpPost(...,%s,...)\n", lpszFileName);
  30.  
  31.     lRet = WpPost(    NULL,        // hWin
  32.             1,        // count of files
  33.             &lpszFileName,    // file list
  34.             NULL,        // lpcbSiteName
  35.             NULL,        // lpszSiteName
  36.             NULL,        // lpcbURL
  37.             NULL,        // lpszURL
  38.             0 );        // flags
  39.     
  40.     printf("WpPost returned %d\n", lRet);
  41.     
  42.     return lRet;
  43. }
  44.  
  45. LONG
  46. ListSites()
  47. {
  48.     static TCHAR    buffer[8192];
  49.     LPWPSITEINFO    lpbSites;
  50.     DWORD        cSites, cbSites, lRet, i;
  51.  
  52.     cbSites = sizeof( buffer );
  53.     cSites = 0;
  54.     lpbSites = (LPWPSITEINFO) buffer;
  55.  
  56.     printf("Calling WpListSites()\n");
  57.  
  58.     lRet = WpListSites( &cbSites, lpbSites, &cSites );
  59.  
  60.     printf("WpListSites() returned %d\n", lRet);
  61.  
  62.     if (lRet)
  63.         return lRet;
  64.     
  65.     printf("Total Sites: %d\n", cSites);
  66.  
  67.  
  68.     for (i = 0; i < cSites; i++, lpbSites++)
  69.         printf("%d. SiteName=%s\n", i, lpbSites->lpszSiteName);
  70.     
  71.     return lRet;
  72. }
  73.  
  74. //
  75. // The next function illustrates getting a pointer to the web post
  76. // provider's interface and calling the functions in that interface.
  77. //
  78.  
  79. LONG
  80. AdvancedWebPost( LPTSTR lpszSiteName, LPTSTR lpszFileName )
  81. {
  82.     DWORD    lRet;
  83.     IWPSite    *lpSite = NULL;
  84.     DWORD    cbURL = 0;
  85.  
  86.     printf("Calling WpBindToSite(..., %s, ...)\n", lpszSiteName);
  87.  
  88.     lRet = WpBindToSite(    NULL,        // hWin
  89.                 lpszSiteName,
  90.                 NULL,        // lpszURL
  91.                 0,        // fdwFlags
  92.                 0,        // dwReserved
  93.                 (PVOID *)&lpSite );    // Interface pointer
  94.     
  95.     printf("WpBindToSite returned %d\n", lRet);
  96.  
  97.     if (lRet)
  98.         return lRet;
  99.  
  100.     lRet = lpSite->NetworkConnect(NULL, NULL);
  101.     printf("NetworkConnect returned %d\n", HRESULT_CODE(lRet));
  102.     if (lRet)
  103.         goto cleanup;
  104.  
  105.     lRet = lpSite->ServerLogin(NULL, NULL);
  106.     printf("ServerLogin returned %d\n", HRESULT_CODE(lRet));
  107.     if (lRet)
  108.         goto cleanup;
  109.     
  110.     printf("Calling PostFiles(...,%s,..)\n", lpszFileName);
  111.  
  112.     lRet = lpSite->PostFiles(    1,    // cLocalPaths
  113.                     &lpszFileName,
  114.                     &cbURL,    // lpcbURL
  115.                     NULL,    // lpszURL
  116.                     0 );    // fdwFlags
  117.     
  118.     printf("PostFiles returned %d\n", HRESULT_CODE(lRet));
  119.  
  120.     lRet = lpSite->ServerLogout();
  121.     printf("ServerLogout returned %d\n", HRESULT_CODE(lRet));
  122.     if (lRet)
  123.         goto cleanup;
  124.  
  125.     lRet = lpSite->NetworkDisconnect();
  126.     printf("NetworkDisconnect returned %d\n", HRESULT_CODE(lRet));
  127.  
  128. cleanup:
  129.     lRet = lpSite->Release();
  130.     printf("Release returned %d\n", HRESULT_CODE(lRet));
  131.  
  132.     return lRet;
  133. }
  134. void
  135. usage(void)
  136. {
  137.     printf("Usage: wbpost [-s sitename] [filename]\n");
  138.     printf("       wbpost -l\t\t: lists the web sites\n");
  139.     exit(1);
  140. }
  141.  
  142. int __cdecl
  143. main(int argc, char *argv[])
  144. {
  145.     LPTSTR    lpszSiteName = NULL, lpszFileName = NULL;
  146.     int    fList = 0;
  147.     LONG    lRet;
  148.     char    c;
  149.  
  150.     // parse the arguments
  151.  
  152.     while (--argc > 0 && (*++argv)[0] == '-')
  153.         if (c = *++argv[0])
  154.             switch (c) {
  155.             case 'l':
  156.                 fList = 1;
  157.                 break;
  158.             case 's':
  159.                 if (--argc)
  160.                   lpszSiteName = *++argv;
  161.                 break;
  162.             default:
  163.                 printf("Error: illegal option %c\n", c);
  164.                 usage();
  165.                 break;
  166.             }
  167.     if (argc == 1) {
  168.         lpszFileName = *argv;
  169.         argc--;
  170.     }
  171.     
  172.     if (argc)
  173.         usage();
  174.     
  175.     // call the apis
  176.  
  177.     if (fList)
  178.         lRet = ListSites();
  179.     else if (lpszSiteName)
  180.         lRet = AdvancedWebPost(lpszSiteName, lpszFileName);
  181.     else
  182.         lRet = SimpleWebPost(lpszFileName);
  183.     
  184.     return lRet;
  185. }
  186.